a = int(input())
b = a % 1000
d = 100
e = a // 10 % 100
count = 0
if a > 9999 or a < 1000:
    print("0")
else:
    while a > 0:
        for i in range(1, a+1):
            if a % i == 0:
                count = count + 1
            if count > 2:
                break;
        if count == 2:
            c = a;
            count = 0
            break
        else:
            a = a // 10
            count = 0
            continue
    while b > 0:
        for i in range(1, b+1):
            if b % i == 0:
                count = count + 1
            if count > 2:
                break;
        if count == 2:
            if c < b:
                c = b
            break
        else:
            b = b % (1 * d)
            d = d // 10
            count = 0
            continue
    if c < e:
        c = e
    print(c)
